package com.smt.modules.bus.service.impl;

import com.smt.common.utils.R;
import com.smt.modules.app.utils.QRCodeUtil;
import com.smt.modules.bus.service.ZxingCodeService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.UUID;

/**
 * @author zhangyi
 * @date 2018/11/15 11:45
 */
@Service
public class ZxingCodeServiceImpl implements ZxingCodeService {

    @Override
    public R getUrlImg(HttpServletResponse response,String filePath) {

        String[] urls = new String[]{
                //展示logo图片标识
                "",
                //读取的转换文件流地址文件流地址
                filePath
        };
        /**
         * 生成后的图片路径
         */
        String dir = "";
        /**
         * 二维码自带logo图片路径
         */
        String logoImgPath = "";
        File file = new File(dir);

        //写入图片流
        Arrays.stream(urls).forEach(url -> {
            try {
                QRCodeUtil.encode(url, logoImgPath, new FileOutputStream(file+"\\"+UUID.randomUUID()+".jpg"), true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        return null;
    }
}
